package br.inf.mensageiro.view.listener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.InetAddress;
import java.net.MulticastSocket;

import br.inf.mensageiro.multicast.ServerMulticast;
import br.inf.mensageiro.pojo.Status;

public class ExitActionListener implements ActionListener{
	private MulticastSocket multicastSoc;
	private InetAddress group;
	
	public ExitActionListener(MulticastSocket multicastSoc,InetAddress group){
		this.multicastSoc=multicastSoc;
		this.group=group;
	}

	public void actionPerformed(ActionEvent e) {
		try{
			ServerMulticast.send(Status.OFF_LINE);
			multicastSoc.leaveGroup(group);
		}catch(IOException ioe){
			ioe.printStackTrace();
		}
		System.exit(0) ;
     }	
}
